/**
 * Copyright (c) 2013 Tianjian, Inc. All rights reserved.
 * This software is the confidential and proprietary information of 
 * Tianjian, Inc. You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the 
 * license agreement you entered into with Tianjian.
 */
package prj.carmap.mobile.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * TODO
 * <p>
 * Title: MyViewPager.java
 * </p>
 * <p>
 * Copyright: Copyright (c) 2013
 * </p>
 * <p>
 * Company: Tianjian
 * </p>
 * <p>
 * team: TianjianTeam
 * </p>
 * <p>
 * 
 * @author: cheng
 *          </p>
 * @date 2014-5-27����11:45:59
 * @version 1.0
 * 
 */
public class MyViewPager extends ViewPager {
	
	private boolean mViewTouchMode = false;

	public MyViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		
	}
	
	 public void setViewTouchMode(boolean b) {  
	        if (b && !isFakeDragging()) {  
	            //ȫȨ���ƻ����¼�  
	            beginFakeDrag();  
	        } else if (!b && isFakeDragging()) {  
	            //��ֹ���ƻ����¼�  
	            endFakeDrag();  
	        }  
	        mViewTouchMode = b;  
	    }  
	  
	    /** 
	     * ��mViewTouchModeΪtrue��ʱ��ViewPager�����ص���¼�������¼�������View���� 
	     */  
	    @Override  
	    public boolean onInterceptTouchEvent(MotionEvent event) {  
	        if (mViewTouchMode) {  
	            return false;  
	        }  
	        return super.onInterceptTouchEvent(event);  
	    }  
	  
	    @Override  
	    public boolean onTouchEvent(MotionEvent ev) {  
	        try {  
	            return super.onTouchEvent(ev);  
	        } catch (Exception e) {  
	            return false;  
	        }  
	    }  
	  
	    /** 
	     * ��mViewTouchModeΪtrue���߻������������ҵ�ʱ��ViewPager��������Ƶ���¼��� 
	     * ��������������ViewPager�м���ListView�ȿ��Ի����Ŀؼ�����������֮��Ļ��������г�ͻ 
	     */  
	    @Override  
	    public boolean arrowScroll(int direction) {  
	        if (mViewTouchMode) return false;  
	        if (direction != FOCUS_LEFT && direction != FOCUS_RIGHT) return false;  
	        return super.arrowScroll(direction);  
	    }

}
